package com.zixuan.gulicollege.service_order.controller;


import com.zixuan.gulicollege.common_utils.R;
import com.zixuan.gulicollege.entity.order.Order;
import com.zixuan.gulicollege.entity.ucenter.UcenterMember;
import com.zixuan.gulicollege.service_order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author zixuan
 * @since 2021-05-26
 */
@RestController
@RequestMapping("/service_order/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 生成订单
     * @return
     */
    @PostMapping("/getOrderNumber/{courseId}")
    public R getOrderNumber(@PathVariable String courseId, @RequestBody UcenterMember userInfo) {

        String orderNum = orderService.createOrder(courseId, userInfo);

        return R.ok().data("orderNum", orderNum);
    }

    /**
     * 根据订单号查询订单信息
     * @param orderOn
     * @return
     */
    @GetMapping("/getOrderInfoByOrderOn/{orderOn}")
    public R getOrderInfoByOrderOn(@PathVariable String orderOn) {
        Order orderInfo = orderService.getOrderInfoByOrderOn(orderOn);
        return R.ok().data("orderInfo", orderInfo);
    }

    /**
     * 根据用户信息查询订单信息
     * @param userId
     * @return
     */
    @GetMapping("/getCourseIsBuyByOrder/{userId}/{courseId}")
    public R getOrderBuyByUserInfo(@PathVariable String userId, @PathVariable String courseId) {
        boolean isBuy = orderService.getOrderBuyByUser(userId, courseId);
        return R.ok().data("isBuy", isBuy);
    }





}

